home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: gcc bug w/getenv? (running Linux)
- Date: 6 Feb 1996 19:14:51 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4f8ueb$qcd@solutions.solon.com>
- References: <4f8sue$84d@newsflash.concordia.ca>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4f8sue$84d@newsflash.concordia.ca>,
- Angus C. March <ac_march@ece.concordia.ca> wrote:
- >I seem to suffer this bizarre bug in gcc-2.6.3, that run on Linux 1.2.13. I
- >tried to assigning a getenv() pointer to a varaible of type char *, but I
- >got a warning about assigning an integer to a pointer. I tried this little
- >experiement:
-
- >#include <stdio.h>
-
- >int main()
- >{
- > char *temp;
- > int thingi;
-
- >temp = (char *)getenv("TERM");
-
- Hmm. You're calling getenv, which returns (char *), but there's no
- prototype in scope. Perhaps you'd like to include <stdlib.h>?
-
- >thingi = getenv("TERM");
-
- Assigning a pointer to an int with no cast...
-
- > printf("getenv(term): %s\ntemp: %s\nthingi: %s\n", getenv("TERM"),
- >temp, thingi);
-
- Hmm. Printf with an argument (thingi) not matching the format type.
-
- > return 0;
- >}
- >The results where facinating:
- >getenv(term): vt100
- >temp: vt100
- >thingi: vt100
- > Is this a bona fide bug?
-
- Nope. Your code is illegal on three counts, the first of which is your
- mistake. It looks like gcc/linux/x86 uses the same representation
- for pointers and ints.
-
- Remember to include relevant headers.
-
- (Also, don't print a getenv() without cheking for NULL. Also, use -Wall,
- so the first use of getenv() warns you that you're calling it with no
- prototype in scope.)
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- Using trn? Weird new newsgroup problem? I know the fix! Email me!
- The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
-